{include file="index/header" /}
<body>
<div class="panel admin-panel margin-top" id="add">
  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 增加内容</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="">    
      <div class="form-group">
        <div class="label">
          <label>角色名：</label>
        </div>
        <div class="field">
          {$role_name}
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>权限：</label>
        </div>
        <div class="field">
        <table class="">
          <tr>
          {foreach name='data' item='v' key='k'}
            <?php if(($k-1)%8==0&&($k-1)!=0){ echo "</tr><tr>";}?>
                <td>
                <dl id="dl{$k}" style="margin-left:10px;">
                    <dt><input type="checkbox" name="privilege_id[]" value="{$v.privilege_id}" id="dt{$k}" onclick="checkdd({$k})" <?php if(in_array($v['privilege_id'],$arr)){echo "checked";}?> />&nbsp;&nbsp;{$v.privilege_name}</dt>
                    {foreach name="v.child" item='v1' key='k1'}
                        <dd style="margin-left:10px;" ><input type="checkbox" name="privilege_id[]" value="{$v1.privilege_id}" class="dds{$k}" id="dd{$k}{$k1}"  onclick="checkdt({$k},{$k1})"  <?php if(in_array($v1['privilege_id'],$arr)){echo "checked";}?>/>&nbsp;&nbsp;{$v1.privilege_name}</dd>
                    {/foreach}
                </dl>
                </td>
            {/foreach}
          </table>
        </div>
        <input type="hidden" name="role_id" value="{$role_id}">
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
</body></html>
<script>
   /**
     * 点击dt标签中的input时，默认选中旗下的子权限
     * @param  {[type]} id [description]
     * @return {[type]}    [description]
     */
        function checkdd(id){
            //alert(id);
            //alert($('#dt'+id).prop('checked'));
            if($('#dt'+id).prop('checked') == true){
                $('#dl'+id+'>dd>input').prop('checked',true);
            }else{
                $('#dl'+id+'>dd>input').prop('checked',false);
            }
        }
    /**
     * 点击dd下的input标签时，默认选中其顶级权限
     * @param  {[type]} id  [description]
     * @param  {[type]} id1 [description]
     * @return {[type]}     [description]
     */
       function checkdt(id,id1){
        var owncheck = $('.dds'+id+':checked').length;
           //alert($('#dd'+id+id1).prop('checked'));
           if($('#dd'+id+id1).prop('checked')==true){
               $('#dl'+id+'>dt>input').prop('checked',true);
           }
           if(owncheck == 0){
                $('#dl'+id+'>dt>input').prop('checked',false);
           }
       }

</script>